{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "ename": "IOError",
     "evalue": "[Errno 2] No such file or directory: 'orcl-2000.csv'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mIOError\u001b[0m                                   Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-1-f786d1b471f7>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m     14\u001b[0m \u001b[1;31m# Load the yahoo feed from the CSV file\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     15\u001b[0m \u001b[0mfeed\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0myahoofeed\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mFeed\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 16\u001b[1;33m \u001b[0mfeed\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0maddBarsFromCSV\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"orcl\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"orcl-2000.csv\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     17\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     18\u001b[0m \u001b[1;31m# Evaluate the strategy with the feed's bars.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mC:\\Users\\yan.zhang\\AppData\\Local\\Continuum\\Anaconda2\\lib\\site-packages\\pyalgotrade\\barfeed\\yahoofeed.pyc\u001b[0m in \u001b[0;36maddBarsFromCSV\u001b[1;34m(self, instrument, path, timezone)\u001b[0m\n\u001b[0;32m    142\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    143\u001b[0m         \u001b[0mrowParser\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mRowParser\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mgetDailyBarTime\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mgetFrequency\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mtimezone\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m__sanitizeBars\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 144\u001b[1;33m         \u001b[0mcsvfeed\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mBarFeed\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0maddBarsFromCSV\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0minstrument\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mpath\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mrowParser\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32mC:\\Users\\yan.zhang\\AppData\\Local\\Continuum\\Anaconda2\\lib\\site-packages\\pyalgotrade\\barfeed\\csvfeed.pyc\u001b[0m in \u001b[0;36maddBarsFromCSV\u001b[1;34m(self, instrument, path, rowParser)\u001b[0m\n\u001b[0;32m    116\u001b[0m         \u001b[1;31m# Load the csv file\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    117\u001b[0m         \u001b[0mloadedBars\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 118\u001b[1;33m         \u001b[0mreader\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mcsvutils\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mFastDictReader\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mopen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mpath\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"r\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfieldnames\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mrowParser\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mgetFieldNames\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdelimiter\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mrowParser\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mgetDelimiter\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    119\u001b[0m         \u001b[1;32mfor\u001b[0m \u001b[0mrow\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mreader\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    120\u001b[0m             \u001b[0mbar_\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mrowParser\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mparseBar\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mrow\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mIOError\u001b[0m: [Errno 2] No such file or directory: 'orcl-2000.csv'"
     ]
    }
   ],
   "source": [
    "from pyalgotrade import strategy\n",
    "from pyalgotrade.barfeed import yahoofeed\n",
    "\n",
    "\n",
    "class MyStrategy(strategy.BacktestingStrategy):\n",
    "    def __init__(self, feed, instrument):\n",
    "        strategy.BacktestingStrategy.__init__(self, feed)\n",
    "        self.__instrument = instrument\n",
    "\n",
    "    def onBars(self, bars):\n",
    "        bar = bars[self.__instrument]\n",
    "        self.info(bar.getClose())\n",
    "\n",
    "# Load the yahoo feed from the CSV file\n",
    "feed = yahoofeed.Feed()\n",
    "feed.addBarsFromCSV(\"orcl\", \"orcl-2000.csv\")\n",
    "\n",
    "# Evaluate the strategy with the feed's bars.\n",
    "myStrategy = MyStrategy(feed, \"orcl\")\n",
    "myStrategy.run()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
